<?php
namespace App\Http\Controllers\Front;

use App\Service\Front\DesignDemandService;
use Illuminate\Http\Request;

class DesignDemandController extends BaseController
{
    //业务

    public function __construct(DesignDemandService $service)
    {
        $this->db = $service;
    }

    //列表
    public function getIndex(Request $request)
    {
        //header("Access-Control-Allow-Origin: *");
        $cateid = $request->get('cate_id', 0);
        $pages['start'] = $request->get('page', 1);
        $pages['limit'] = $request->get('limit', 10);
        $res = $this->db->getIndex($cateid, $pages);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //添加
    public function add(Request $request)
    {
        //header("Access-Control-Allow-Origin: *");
        $token = $request->post('token', '');
        $pas['cid'] = $this->db->cidByToken($token);
        $pas['title'] = $request->post('title', '');
        $pas['cate_id'] = $request->post('cate_id', 0);
        $pas['price'] = $request->post('price', 0);
        $pas['detail'] = $request->post('detail', ''); //描述富文本
        $pas['cr_detail'] = $request->post('cr_detail', ''); //设计描述
        $pas['work_type'] = $request->post('work_type', 0); //1兼职2全职
        $pas['work_skill'] = $request->post('work_skill', ''); //工作技能
        $pas['work_year'] = $request->post('work_year', 0); //工作年限
        $pas['education'] = $request->post('education', 0); //0无，1小学，2初中，3高中，4大专，5本科，6研究生，7博士
        $pas['area_id'] = $request->post('area_id', 0); //地区ID
        $pas['day_hour'] = $request->post('day_hour', 0); //日均工时
        $pas['item_hour'] = $request->post('item_hour', 0); //项目时长
        $pas['team_num'] = $request->post('team_num', 0); //参与人数
        $pas['deadline'] = $request->post('deadline', ''); //截止时间
        if (!$pas['cid']) {
            return $this->toJson(-2, '你的企业身份无效');
        }
        if (!$pas['title']) {
            return $this->toJson(-2, '项目名称必须的');
        }
        if (!$pas['price']) {
            return $this->toJson(-2, '项目价格必须的');
        }
        $res = $this->db->add($pas);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }
}